<script>
function removeLanguage(language_id) {
  Tr8n.Utils.ajax('/tr8n/tools/language_selector/remove_language', {
    parameters: {language_id: language_id}
  });
  Tr8n.Effects.hide('lang_' + language_id);
}
</script>

<div class="inner" <%=tr8n_dir_attribute_tag%>>
  <div class="hd" style="background-color:white;font-size:12px;">
    <div style="<%=tr8n_style_attribute_tag('float', 'right')%>;">
        <%=link_to_function(image_tag("tr8n/close.gif", :style => "border:0px; padding:5px;", :alt=>trla("Close")), "hideLightbox()") %>
    </div>
    <div style="padding-top:3px">
        <%=tra("Select your language") %>
    </div>
  </div>
  <div class="bd">
    <div style="margin-top:2px; margin-bottom: 5px;">
        <% if @user_languages and not @user_languages.empty? %>
        <div style="color:grey; font-size:11px; padding-bottom:3px; font-weight:bold;">
            <%=tra("Your Languages") %>
        </div>
        <div style="max-height:65px; overflow: auto; margin-bottom:5px; border:solid 1px #e8e8e8; padding:5px; background-color:white;">
            <ul class="language_list">
                <% @user_languages.each do |language| %>
                <% next unless language %>
                <li id="lang_<%=language.id%>">
                    <% if language.default? %>
                      <div style="font-size:8px; <%=tr8n_style_attribute_tag('float', 'right')%>; color:#ccc;">
                         <%=tra('default', 'Default language label') %>
                      </div>
                    <% else %>
                      <div style="font-size:8px; <%=tr8n_style_attribute_tag('float', 'right')%>; color:#ccc;">
                        <%= "#{language.completeness || 0}%" if Tr8n::Config.enable_language_stats? %>
                        <span onClick="removeLanguage('<%=language.id%>')">
                           <%=image_tag("tr8n/close.gif", :style=>"width:5px; padding-right:3px; padding-left:3px;") %>
                        </span>
                      </div>
                    <% end %>
                    
                    <div onClick="Tr8n.postMessage({'subject': 'language_selector', 'action': 'change', 'locale': '<%=language.locale%>'}, '<%=params[:origin]%>')" style="width:80%">
                        <%= tr8n_language_flag_tag(language) %>
                        <span dir="ltr">
                          <% if language == tr8n_current_language %>
                              <strong><%=language.full_name %></strong>
                          <% else %>
                              <%=language.full_name %>
                          <% end %>
                        </span>
                    </div>
                </li>
                <% end %>
            </ul>
        </div>
        <div style="color:grey; font-size:11px; padding-bottom:3px; font-weight:bold;">
            <%=tra("Other Languages") %>
        </div>
        <% end %>

        <div id="tr8n_languages_list" style="max-height: 200px; overflow: auto; border:solid 1px #e8e8e8; padding:5px; background-color:white;">
            <ul class="language_list">
                <% @all_languages.each do |language| %>
                <li onClick="Tr8n.postMessage({'subject': 'language_selector', 'action': 'change', 'locale': '<%=language.locale%>'}, '<%=params[:origin]%>')">
                    <% if Tr8n::Config.enable_language_stats? %>
                        <span style="font-size:8px; <%=tr8n_style_attribute_tag('float', 'right')%>; color:#ccc;"><%= "#{language.default? ? '100' : (language.completeness || 0)}%" %></span>
                    <% end %>
                    <%= tr8n_language_flag_tag(language) %>
                    <span dir="ltr">
                        <%= language.full_name %>
                    </span>
                </li>
                <% end %>
            </ul>
        </div>
    </div>
    
    <div style="padding-bottom:40px;">
        <% if tr8n_current_user_is_translator? and tr8n_current_translator_can_translate_remote_application? %>
          <% if @inline_translations_allowed %>
            <div style="padding-top:5px; padding-bottom:5px; font-size: 11px; font-weight:bold; ">
                <% if @inline_translations_enabled %>
                    <%=link_to_function(tra("Disable Inline Translations"), "Tr8n.postMessage({'subject': 'language_selector', 'action': 'toggle_inline_translations'}, '#{params[:origin]}')") %>
                <% else %>
                    <%=link_to_function(tra("Enable Inline Translations"), "Tr8n.postMessage({'subject': 'language_selector', 'action': 'toggle_inline_translations'}, '#{params[:origin]}')") %>
                <% end %>
                <div style="font-weight:normal; color:grey;"><%=tra("Use right-mouse-click or ctr+click to translate the site.") %></div>
            </div>
          <% end %>
        
          <div style="padding-top:5px; padding-bottom:5px;font-size: 11px; font-weight:bold;">
              <%=link_to(tra("Translation Tools"), "/tr8n/translator", :target => "_top") %>
              <div style="font-weight:normal; color:grey;"><%=tra("Search for translations by other users, vote on translations or add your own translations.") %></div>
          </div>

          <% if tr8n_current_translator.manager? %>
            <div style="padding-top:5px; padding-bottom:5px;font-size: 11px; font-weight:bold;">
                <%=link_to(tra("Manage Language"), "/tr8n/language", :target => "_top") %>
                <span style="color: grey; font-size: 10px; padding-left:0.5em; font-style:italic;">language admins only</span>
                <div style="font-weight:normal; color:grey;"><%=tra("Change language native name and define language rules.") %></div>
            </div>
          <% end %>

        <% else %>
            <% if false # TODO: add domain check %>
                <div style="padding-top:5px; padding-bottom:5px;font-size: 11px; font-weight:bold;">
                    <%=link_to(tra("Become a Translator"), "/tr8n/translator/registration", :target => "_top") %>
                    <div style="font-weight:normal; color:grey;"><%=tra("Allows you to submit and vote on translations") %></div>
                </div>
            <% end %>
        <% end %>

        <% if tr8n_current_user_is_admin? %>
          <div style="padding-top:5px; padding-bottom:5px;font-size: 11px; font-weight:bold;">
              <%=link_to(tra("Configure tr8n"), "/tr8n/admin/language", :target => "_top") %>
              <span style="color: grey; font-size: 10px; padding-left:0.5em; font-style:italic;">tr8n admins only</span>
              <div style="font-weight:normal; color:grey;"><%=tra("Manage translators, languages and translations.") %></div>
          </div>
        <% end %>
        
        <div class="ft" style="font-size:10px;height:10px;">
            <%=tr8n_help_icon_tag %>
            &nbsp;<%=tra("Click this icon to view [link: translation help] in a new window.", "", :link => lambda{|txt| link_to(txt, {:controller => "/tr8n/help", :action => :index}, :target => "new")}) %>
        </div>
    </div>
  </div>
</div>
